package com.ruoyi.web.controller.selfBookingConfig;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.ScanOrderSettings;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BookingRule;
import com.ruoyi.system.service.IBookingRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预订规则，用于记录与预订相关的规则和限制Controller
 *
 * @author ruoyi
 * @date 2025-05-13
 */
@Api(tags="预订规则")
@RestController
@RequestMapping("/system/bookingRule")
public class BookingRuleController extends BaseController
{
    @Autowired
    private IBookingRuleService bookingRuleService;

    /**
     * 查询预订规则列表
     */
    @ApiOperation("查询预订规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookingRule bookingRule)
    {
        startPage();
        List<BookingRule> list = bookingRuleService.selectBookingRuleList(bookingRule);
        return getDataTable(list);
    }

    /**
     * 导出预订规则列表
     */
    @ApiOperation("导出预订规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "预订规则，用于记录与预订相关的规则和限制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookingRule bookingRule)
    {
        List<BookingRule> list = bookingRuleService.selectBookingRuleList(bookingRule);
        ExcelUtil<BookingRule> util = new ExcelUtil<BookingRule>(BookingRule.class);
        util.exportExcel(response, list, "预订规则，用于记录与预订相关的规则和限制数据");
    }

    /**
     * 获取预订规则详细信息
     */
    @ApiOperation("获取预订规则详细信息")
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bookingRuleService.selectBookingRuleById(id));
    }

    /**
     * 新增预订规则
     */
    @ApiOperation("新增预订规则")
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "预订规则，用于记录与预订相关的规则和限制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookingRule bookingRule)
    {
        return toAjax(bookingRuleService.insertBookingRule(bookingRule));
    }

    /**
     * 修改预订规则
     */
    @ApiOperation("修改预订规则")
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "预订规则，用于记录与预订相关的规则和限制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookingRule bookingRule)
    {
        return toAjax(bookingRuleService.updateBookingRule(bookingRule));
    }

    /**
     * 删除预订规则信息
     */
    @ApiOperation("删除预订规则信息")
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "预订规则，用于记录与预订相关的规则和限制", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookingRuleService.deleteBookingRuleByIds(ids));
    }

    /**
     * 根据门店ID查询预订规则详情
     */
    @ApiOperation("根据门店ID查询预订规则详情")
    @PreAuthorize("@ss.hasPermi('system:settings:query')")
    @GetMapping("/detail/{storeId}")
    public AjaxResult getTableSettingsDetail(@PathVariable("storeId") Long storeId) {
        BookingRule bookingRule = bookingRuleService.selectByStoreId(storeId);
        return success(bookingRule);
    }

}
